import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  //给内部的脚手架 配置解析
  resolve: {
    //路径别名的配置
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },

  //配置代理
  server: {
    proxy: {
      // /path是当前代理的前缀,将来要添加在请求上,用来查找使用哪一个代理
      "/path": {
        //目标地址
        target: "https://api.github.com/",
        //开启代理
        changeOrigin: true,
        //重写路径 删除代理前缀
        rewrite: (path) => path.replace(/^\/path/, ""),
      },

      "/api1": {
        //目标地址
        target: "http://localhost:8888",
        //开启代理
        changeOrigin: true,
        //重写路径 删除代理前缀
        rewrite: (path) => path.replace(/^\/api1/, ""),
      },
    },
  },
});
